package work.test01waitandnotify1;

import sun.misc.RequestProcessor;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadDemo {
    public static void main(String[] args) {
        /*
        假设包裹箱只能存100个包裹
        如果快递员存满了100个，就进入等待，当用户来取后，就唤醒快递员继续往箱子里存包裹
        如果包裹箱里没有包裹，则用户就进入等待，当快递员存入包裹后，就唤醒用户来取包裹
         */

        //创建Runnable接口对象
        DepositParcel dp = new DepositParcel();
        WithdrawParcel wp = new WithdrawParcel();

        //创建线程对象
        Thread t1 = new Thread(dp);
        Thread t2 = new Thread(wp);

        //修改线程名字
        t1.setName("快递员:");
        t2.setName("用户:");

        //开启线程
        t2.start();
        t1.start();


//        //1、获取线程池对象
//        ExecutorService pool1 = Executors.newFixedThreadPool(2);
//
//        //2、提交任务
//        pool1.submit(new WithdrawParcel());
//        pool1.submit(new DepositParcel());
//
//        //3、销毁线程池
//        pool1.shutdown();
    }

}
